import sys

from lib.datebase import Boss

sys.path.append("..")

from base.FipSiteSpider import BossSpider

from base.BaseSpider import TimeIt, ML


class Demo(BossSpider):
    __version__ = "version: 1.0"

    def __init__(self):
        super().__init__()
        self.__Version__ = [self.__class__.__name__, self.__version__]
        self.conn_str = "mysql+pymysql://root:admin@localhost:3306/test_db"
        self.table = Boss().table

    def proc_row(self, crawl_page, keywords):
        for keyword in keywords:
            self.search_jobs(keyword)
            self.sleep(20)
            for _ in range(crawl_page):
                self.for_job_list()
                self.next_page()
                self.sleep(8)

    def item(self):
        self.login_website()
        self.sleep(60)
        self.proc_row(self.get_settings_field('crawl_page'), self.get_settings_field('keywords'))

    @TimeIt
    def run(self):
        ML.info(": ".join(self.__Version__))
        try:
            self.item()
            print('程序结束...')
        except Exception as e:
            # print(e)
            self.print_exc()


if __name__ == '__main__':
    Demo().run
